<template>
  <div class="common-nav-bar">
    <div class="nav-left">
      <div class="back-button" @click="backToHome">
        <Icon type="ios-arrow-back" size="20" />
        <span>返回首页</span>
      </div>
      <h1 class="page-title">{{ pageTitle }}</h1>
    </div>
    <div class="nav-right">
      <div class="settings-button" @click="showLogoutModal = true">
        <Icon type="ios-settings" size="20" />
        <span>设置</span>
      </div>
    </div>
    
    <!-- 注销确认模态框 -->
    <div v-if="showLogoutModal" class="modal-overlay" @click="showLogoutModal = false">
      <div class="modal-content" @click.stop>
        <h3>确认注销</h3>
        <p>您确定要注销登录吗？</p>
        <div class="modal-buttons">
          <button @click="showLogoutModal = false" class="cancel-btn">取消</button>
          <button @click="logout" class="confirm-btn">确认</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CommonNavBar',
  props: {
    pageTitle: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      showLogoutModal: false
    }
  },
  methods: {
    backToHome() {
      this.$router.push('/dashboard').catch(err => {
        if (err.name !== 'NavigationDuplicated') {
          console.error('返回首页导航错误:', err)
        }
      })
    },
    logout() {
      // 清除登录状态
      localStorage.removeItem('access_token')
      localStorage.removeItem('refresh_token')
      localStorage.removeItem('user_info')
      
      // 跳转到登录页面
      this.$router.push('/login').catch(err => {
        if (err.name !== 'NavigationDuplicated') {
          console.error('注销跳转错误:', err)
        }
      })
      
      // 显示成功消息
      this.$Message.success('注销成功')
      
      // 关闭模态框
      this.showLogoutModal = false
    }
  }
}
</script>

<style lang="less" scoped>
.common-nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: rgba(7, 19, 50, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #1a3c58;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  z-index: 1000;
  
  .nav-left {
    display: flex;
    align-items: center;
    gap: 20px;
    
    .back-button {
      display: flex;
      align-items: center;
      padding: 8px 16px;
      background: rgba(117, 222, 239, 0.1);
      border: 1px solid #75deef;
      border-radius: 20px;
      cursor: pointer;
      transition: all 0.3s ease;
      
      &:hover {
        background: rgba(117, 222, 239, 0.2);
        box-shadow: 0 0 10px rgba(117, 222, 239, 0.3);
      }
      
      :deep(.ivu-icon) {
        color: #75deef;
        margin-right: 8px;
      }
      
      span {
        color: #75deef;
        font-size: 14px;
      }
    }
    
    .page-title {
      font-size: 24px;
      font-weight: bold;
      background: linear-gradient(45deg, #75deef, #4ecdc4);
      -webkit-background-clip: text;
      background-clip: text;
      -webkit-text-fill-color: transparent;
      margin: 0;
      text-shadow: 0 0 20px rgba(117, 222, 239, 0.5);
    }
  }
  
  .nav-right {
    display: flex;
    align-items: center;
    
    .settings-button {
      display: flex;
      align-items: center;
      padding: 10px 20px;
      background: rgba(117, 222, 239, 0.1);
      border: 1px solid #75deef;
      border-radius: 25px;
      cursor: pointer;
      transition: all 0.3s ease;
      
      &:hover {
        background: rgba(117, 222, 239, 0.2);
        box-shadow: 0 0 15px rgba(117, 222, 239, 0.3);
      }
      
      :deep(.ivu-icon) {
        color: #75deef;
        margin-right: 8px;
      }
      
      span {
        color: #75deef;
        font-size: 14px;
      }
    }
  }
  
  .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    
    .modal-content {
      background: rgba(7, 19, 50, 0.95);
      border: 1px solid #1a3c58;
      border-radius: 12px;
      padding: 30px;
      width: 400px;
      text-align: center;
      
      h3 {
        color: #75deef;
        margin-bottom: 15px;
        font-size: 20px;
      }
      
      p {
        color: #999;
        margin-bottom: 25px;
        font-size: 16px;
      }
      
      .modal-buttons {
        display: flex;
        justify-content: center;
        gap: 15px;
        
        button {
          padding: 10px 25px;
          border: none;
          border-radius: 25px;
          cursor: pointer;
          font-size: 14px;
          transition: all 0.3s ease;
          
          &.cancel-btn {
            background: rgba(153, 153, 153, 0.2);
            color: #999;
            border: 1px solid #999;
            
            &:hover {
              background: rgba(153, 153, 153, 0.3);
            }
          }
          
          &.confirm-btn {
            background: rgba(255, 107, 107, 0.2);
            color: #ff6b6b;
            border: 1px solid #ff6b6b;
            
            &:hover {
              background: rgba(255, 107, 107, 0.3);
            }
          }
        }
      }
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .common-nav-bar {
    height: 60px;
    padding: 0 15px;
    
    .nav-left {
      gap: 15px;
      
      .back-button {
        padding: 6px 12px;
        
        span {
          font-size: 12px;
        }
      }
      
      .page-title {
        font-size: 18px;
      }
    }
    
    .nav-right {
      .settings-button {
        padding: 8px 16px;
        
        span {
          font-size: 12px;
        }
      }
    }
  }
}
</style> 